package com.alick.third_push.getui;

import android.content.Context;
import android.util.Log;

import com.igexin.sdk.GTIntentService;
import com.igexin.sdk.message.GTCmdMessage;
import com.igexin.sdk.message.GTTransmitMessage;

import common.utils.BLog;

/**
 * 继承 GTIntentService 接收来自个推的消息, 所有消息在线程中回调, 如果注册了该服务, 则务必要在 AndroidManifest中声明, 否则无法接受消息<br>
 * onReceiveMessageData 处理透传消息<br>
 * onReceiveClientId 接收 cid <br>
 * onReceiveOnlineState cid 离线上线通知 <br>
 * onReceiveCommandResult 各种事件处理回执 <br>
 */
public class GeTuiIntentService extends GTIntentService {


    public GeTuiIntentService() {

    }

    @Override
    public void onReceiveServicePid(Context context, int pid) {
        BLog.i("pid:"+pid+"--->onReceiveServicePid()");
    }

    @Override
    public void onReceiveMessageData(Context context, GTTransmitMessage msg) {
        String extraJson = null;
        /*try {
            extraJson = new String(msg.getPayload());
            NotificationMsg notificationMsg = JsonUtils.parseJson2Bean(extraJson, NotificationMsg.class);
            notificationMsg.setPush_channel(BizContant.PushChannel.GETUI);
            PushNotificationManager.getInstance().onReceiveNotification(context, notificationMsg);
        } catch (Exception e) {
            e.printStackTrace();
            BLog.e("个推收到透传消息,解析失败异常:"+e.getMessage()+",消息:"+extraJson);
            MobclickAgent.reportError(context,"个推收到透传消息,解析失败异常:"+e.getMessage()+",消息:"+extraJson);
        }*/
    }

    @Override
    public void onReceiveClientId(Context context, String clientid) {
        Log.i(TAG, "个推推送注册成功,onReceiveClientId -> " + "clientid = " + clientid);
    }

    @Override
    public void onReceiveOnlineState(Context context, boolean online) {
        BLog.i("online:"+online+"--->onReceiveOnlineState()");
    }

    @Override
    public void onReceiveCommandResult(Context context, GTCmdMessage cmdMessage) {
        try {
            BLog.i("cmdMessage:"+cmdMessage.toString()+"--->onReceiveCommandResult()");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}